package com.linktrip.devicesmanager.main;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import com.linktrip.devicemanager.util.ByteUtil;

public class DeviceTestMain2 {
	public static byte[] temp = { 0x36, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, (byte) 0xa5, 0x0a, 0x07, 0x56,
			(byte) 0x97, (byte) 0xac, (byte) 0xc5, 0x09, 0x01, 0x01, 0x64, 0x11, 0x00, 0x00, 0x00, 0x2b, (byte) 0xda,
			0x1c, (byte) 0xe7, 0x36, 0x19, 0x3f, 0x40, 0x32, 0x1e, (byte) 0xa5, 0x12, (byte) 0x9e, 0x60, 0x5e, 0x40,
			(byte) 0xe1, 0x07, 0x05, 0x05, 0x13, 0x06, 0x32, 0x00, 0x01, 0x19, 0x2c, 0x1e, 0x2a, 0x00, 0x00, 0x74 };
	/*
	 * public static byte[] temp2 = { 0x36, 0x00, 0x02, 0x00, 0x01, 0x03, 0x00,
	 * 0x00, 0x24, 0x47, 0x56, 0x07, 0x58, (byte) 0xc8, (byte) 0xfa, (byte)
	 * 0xa6, 0x0a, 0x01, 0x01, 0x5b, 0x11, 0x00, 0x00, 0x03, (byte) 0xcf, (byte)
	 * 0xbe, (byte) 0xf2, 0x20, 0x3d, 0x19, 0x3f, 0x40, 0x23, (byte) 0x83,
	 * (byte) 0xdc, 0x45, (byte) 0x98, 0x60, 0x5e, 0x40, (byte) 0xe1, 0x07,
	 * 0x05, 0x15, 0x10, 0x30, 0x2f, 0x00, 0x03, 0x1b, 0x2b, 0x14, 0x29, 0x00,
	 * 0x00, 0x31 };
	 */
	public static byte[] temp2 = { 0x3e, 0x00, 0x02, 0x00, 0x10, 0x4c, 0x00, (byte) 0x80, 0x24, 0x47, 0x56, 0x07, 0x58, (byte) 0xc8,
			(byte) 0xfa, (byte) 0xa6, 0x0d, 0x01, 0x01, 0x5d, 0x11, 0x00, 0x00, 0x4c, (byte) 0x8d, (byte) 0x87, (byte) 0xad, (byte) 0x8f, 0x3d, 0x19, 0x3f, 0x40,
			0x47, (byte) 0xcf, (byte) 0x88, 0x2d, (byte) 0x98, 0x60, 0x5e, 0x40, (byte) 0xe1, 0x07, 0x05, 0x15, 0x11, 0x0e, 0x02, 0x00, 0x03, 0x1d,
			0x2b, 0x14, 0x29, 0x00, 0x00, (byte) 0xcb, (byte) 0xf8, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00 };

	public static int count = 0;

	public static void main(String[] args) throws Exception {
		// new DeviceTestMain().deviceConnector();
		// Socket socket = new Socket("test.linktrip.com", 9000);
		threadCount(100);
	}

	public static void threadCount(int count) {
		for (int i = 0; i < count; i++) {
			new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						doSomeThing();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
	}

	public static void doSomeThing() throws IOException {
		while (true) {
			Socket socket = new Socket("test.linktrip.com", 8877);

			OutputStream out = socket.getOutputStream();
			DataOutputStream dout = new DataOutputStream(out);
			dout.write(temp2);
			dout.flush();
			System.out.println("24378165697ac5b wrote done!");
			DataInputStream dRead = new DataInputStream(socket.getInputStream());

			// short len = 0;
			// len = dRead.readShort();
			// byte[] data = new byte[len];
			// dRead.read(data);
			// ByteUtil.printBytes(data);
			// if(data != null)break;
			String tmp = dRead.readUTF();

			if (tmp != null) {
				System.out.println("tmp:" + tmp);
				break;
			}

			dout.close();
			dRead.close();
			socket.close();

		}
		// do {
		// len = dRead.readShort();
		// if (len > 0) {
		// byte[] data = new byte[len];
		// dRead.read(data);
		// ByteUtil.printBytes(data);
		// }
		// } while (len <= 0);

	}

}